﻿#ifndef JZ_IMAGE_VIEW_H_
#define JZ_IMAGE_VIEW_H_

#include <QGraphicsView>
#include <QGraphicsItem>
#include <QMap>
#include <QPixmap>
#include "JZImageGraphic.h"

class JZGraphicItem : public QGraphicsItem
{
public:
    JZGraphicItem(JZGraphic g);

    virtual QRectF boundingRect() const override;

protected:
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
    void updateBoundingRect();

    JZGraphic m_graphic;
    QRectF m_rect;
};

class JZImageView : public QGraphicsView
{
    Q_OBJECT

public:
    JZImageView();
    ~JZImageView();

    QImage image();
    void setImage(const QImage &image);    
    void clear();

    void initGraphics(const QList<JZGraphic> &graphic);
    void clearGraphics();    

signals:
    void sigCoorColor(QPoint pos,QColor color);

protected:
    void wheelEvent(QWheelEvent *event);
    void mouseMoveEvent(QMouseEvent *event) override;
    void drawBackground(QPainter* painter, const QRectF& r);

    QGraphicsScene *m_scene;
    QImage m_image;
};

#endif